﻿@inject SqlContext _context;
@inject BaseWebElement _baseElement;
@model ContentClass
@{
    int classId = (int)ViewData["ClassId"];
    int page = (int)ViewData["page"];
    string searchText = ViewData["searchText"] as string;
    Expression<Func<Product_Info, bool>> where = m => true;
    if (!searchText.IsNullOrWhiteSpace())
    {
        if (searchText.IsCasNo())
        {
            where = where.And(m => m.CasNo == searchText);
        }
        else
        {
            where = where.And(m => m.ProName.Contains(searchText));
        }
    }
    if (classId == 0)
    {
        where = where.And(m => m.LanguageId == _baseElement.Currentlanguage.Id);
    }
    else
    {
        where = where.And(m => m.ClassId == classId);
    }
    int pageSize = 12;
    var CompanyName = _baseElement.GetWebElement(WebElementType.CompanyName)?.Value;
    string url = _baseElement.GetCurrentlanguageclassHref() + "products?cid=" + classId + "&page={0}";
    var pros = _context.QueryPageList<Product_Info>(where, "Sort desc", page, pageSize);
    ViewData["Title"] = Model.ClassName + " - " + CompanyName;
    var LocationClass = _baseElement.GetCurrentRoute(Model.Id);
    var CurrentlanguageclassHref = _baseElement.GetCurrentlanguageclassHref();
    ViewData["keywords"] = Model.SeoKeywords;
    ViewData["description"] = Model.SeoDescritions;
}
@functions{
    public string GetProductTitleImg(int proId)
    {
        var imgInfo = _context.QueryInfo<Product_Img>(m => m.ProId == proId, "IsTitle desc");
        if (imgInfo != null)
        {
            return imgInfo.Img;
        }
        else
        {
            return "";
        }
    }
}
<div class="wrapper">
    <div class="crumbs">
        <div class="container">
            <p class="weizhi">
                @(_baseElement.QueryLanText("Location"))：<a href="@(CurrentlanguageclassHref)">@(_baseElement.QueryLanText("Home"))</a>
                @if (LocationClass != null && LocationClass.Count > 0)
                {
                    foreach (var item in LocationClass)
                    {
                        @Html.Raw("&gt")<a href="@(item.ClassHref)">@item.ClassName</a>
                    }
                }
            </p>
        </div>
    </div>
    <div class="product">
        <div class="container">
            <ul class="proLis clearfix">
                @{
                    foreach (var pro in pros.data)
                    {
                        <li>
                            <div class="imgBox">
                                <a href="@(CurrentlanguageclassHref)products/detail/@(pro.Id).html"><img src="@GetProductTitleImg(pro.Id)"></a>
                            </div>
                            <div class="txtBox">
                                <a href="@(CurrentlanguageclassHref)products/detail/@(pro.Id).html">@pro.ProName</a>
                                @if (!pro.CasNo.IsNullOrWhiteSpace())
                                {
                                    <P>CAS：@pro.CasNo</P>
                                }
                            </div>
                        </li>
                    }
                }
            </ul>
            <div class="fw-pagination-box divide">
                @Html.Raw(PagingHelper.PagingRaw((int)pros.count, pageSize, page, url, 9))
            </div>
        </div>
    </div>
</div>